<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/manage/common/taglibs.jsp"%>

<script type="text/javascript">
  //Namespace.register("manage.user");
  //var manage.user.refrences = {};

  $(function() {
    $('#user_datagrid').datagrid({
      url:'${pageContext.request.contextPath}/manage/system/user/query.html',
      fit : true,
      fitColumns : true,
      border : false,
      pagination : true,
      idField : 'id',
      pageSize : 20,
      pageList : [ 10, 20, 30, 40, 50 ],
      sortName : 'id',
      sortOrder : 'desc',
      checkOnSelect : true,
      selectOnCheck : true,
      loadFilter:function(data){
    	  if(!data.success){
    		  alert(data.message);
    	  	  return null;
    	  }
    	  //manage.user.refrences = data.data;
          return data;  
      },
      frozenColumns : [ [ {
        field : 'id',
        title : '编号',
        width : 150,
        checkbox : true
      } ] ],
      columns : [ [ {
          field : 'loginid',
          title : '登录名称',
          width : 100,
          sortable : true
        }, {
        field : 'name',
        title : '姓名',
        width : 100,
        sortable : true
      }, {
          field : 'createTime',
          title : '创建时间',
          width : 120,
          formatter : function(value, row, index) {
        	  return formatDate(value);
          }
        },{
        field : 'email',
        title : 'E-Mail',
        width : 150,
        sortable : true
      },{
          field : 'roles',
          title : '角色',
          width : 150,
          formatter : function(value, row, index) {
        	  if(value){
        		  return $(value[0]).attr("name"); 
        	  }else{
        		  return "";
        	  }
            }
        }, {
        field : 'status',
        title : '状态',
        width : 80,
        formatter : function(value, row, index) {
        	//return manage.user.refrences.allStatus[value];
          }
      }, {
          field : 'userType',
          title : '用户类型',
          width : 80,
          formatter : function(value, row, index) {
        	  //return manage.user.refrences.allUserTypes[value];
            }
        }, {
        field : 'action',
        title : '动作',
        width : 100,
        formatter : function(value, row, index) {
            return '<a onclick="manage_user_edit('+row.id+');" href="#">编辑</a>';
        	//return formatString('<img onclick="admin_yhgl_editFun(\'{0}\');" src="{1}"/>&nbsp;<img onclick="admin_yhgl_deleteFun(\'{2}\');" src="{3}"/>&nbsp;<img onclick="admin_yhgl_modifyPwdFun(\'{4}\');" src="{5}"/>', 0, '${pageContext.request.contextPath}/style/images/extjs_icons/pencil.png', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/cancel.png', row.id, '${pageContext.request.contextPath}/style/images/extjs_icons/lock/lock_edit.png');
        }
      } ] ],
      toolbar : [ {
        text : '增加',
        iconCls : 'icon-add',
        handler : function() {
        	show_manage_user_add();
        }
      }, '-', {
        text : '批量删除',
        iconCls : 'icon-remove',
        handler : function() {
          admin_yhgl_removeFun();
        }
      }, '-', {
        text : '批量设置角色',
        iconCls : 'icon-edit',
        handler : function() {
          admin_yhgl_modifyRoleFun();
        }
      }, '-' ]
    });
    

  });
  
  
  
  function show_manage_user_add(){
		$('#user_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/manage/system/user/create.html',
			width : 520,
			height: 450,
			modal : true,
			iconCls:'icon-save',
			title : '添加用户',
			buttons : [ {
				text : '增加',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#manage_user_addForm').form('submit', {
						url : '${pageContext.request.contextPath}/manage/system/user/addNew.html',
						success : function(result) {
							try {
								var r = $.parseJSON(result);
								if (r.success) {
									$('#user_datagrid').datagrid('insertRow', {
										index : 0,
										row : r.entity
									});
									d.dialog('destroy');
								}
								$.messager.show({title : '提示',msg : r.message });
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
  }
  
  
  
	function manage_user_edit(id) {
		$('#user_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/manage/system/user/edit.html?id='+id,
			width : 520,
			height : 450,
			modal : true,
			title : '编辑用户',
			buttons : [ {
				text : '编辑',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#admin_yhglEdit_editForm').form('submit', {
						url : '${pageContext.request.contextPath}/manage/system/user/update.html',
						success : function(result) {
							try {
								var r = $.parseJSON(result);
								if (r.success) {
									$('#user_datagrid').datagrid('updateRow', {
										index : $('#user_datagrid').datagrid('getRowIndex', id),
										row : r.entity
									});
									d.dialog('destroy');
								}
								$.messager.show({
									title : '提示',
									msg : r.message
								});
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			},
			onLoad : function() {
				var index = $('#admin_yhgl_datagrid').datagrid('getRowIndex', id);
				var rows = $('#admin_yhgl_datagrid').datagrid('getRows');
				var o = rows[index];
				o.roleIds = stringToList(rows[index].roleIds);
				$('#admin_yhglEdit_editForm').form('load', o);
			}
		});
	}
  
  
  
  function userSearch(){
	  var queryParams = serializeObject($('#user_searchForm'));
	  $('#user_datagrid').datagrid('load', queryParams);
  }
  
</script>



<div class="easyui-layout" data-options="fit : true,border : false">
  <div data-options="region:'north',border:false" style="height: 40px; overflow: hidden;" align="left">
    <form id="user_searchForm">
      <table class="tableForm">
        <tr>
          <td align="left">登录名:<input type="text" name="search_LIKE_loginid" /> 姓名:<input type="text" name="search_LIKE_name" /> 创建时间:<input name="createdatetimeStart"
            onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" />至<input name="createdatetimeEnd" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" /> <a
            href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="userSearch();">过滤条件</a> <a href="javascript:void(0);"
            class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="admin_yhgl_cleanFun();">清空条件</a>
          </td>
        </tr>
      </table>
    </form>
  </div>
  <div data-options="region:'center',border:false">
    <table id="user_datagrid"></table>
  </div>
</div>
